package com.wing.system.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.product.model.entity.ProductWorkmanship;
import com.wing.product.model.response.ProductWorkmanshipVO;
import com.wing.system.dao.SpaceCharacterDao;
import com.wing.system.model.entity.SpaceCharacter;
import com.wing.system.model.request.SpaceCharacterForm;
import com.wing.system.model.response.SpaceCharacterVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 空间性质-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class SpaceCharacterServiceImpl extends ServiceImpl<SpaceCharacterDao, SpaceCharacter> implements SpaceCharacterService {

    @Override
    public int add(SpaceCharacterForm spaceCharacterForm) {

        //校验

        SpaceCharacter spaceCharacter =new SpaceCharacter();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(SpaceCharacter.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(spaceCharacterForm, spaceCharacter, copyOptions);

        return baseMapper.insert(spaceCharacter);
    }

    @Override
    public List<SpaceCharacterVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<SpaceCharacterVO> pageList4app(Page page, Map<String, Object> params) {
        List<SpaceCharacterVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public SpaceCharacterVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    @Transactional
    public int enable(Long id) {
        SpaceCharacterVO spaceCharacterVO=baseMapper.get4appById(id);
        if (spaceCharacterVO!=null){
            SpaceCharacter spaceCharacter=new SpaceCharacter();
            spaceCharacter.setId(id);
            spaceCharacter.setDeleted(true);
            int updateCount=baseMapper.updateById(spaceCharacter);
            return updateCount;
        }

        return 0;
    }

    @Override
    @Transactional
    public int disable(Long id) {
        SpaceCharacterVO spaceCharacterVO=baseMapper.get4appById(id);
        if (spaceCharacterVO!=null){
            SpaceCharacter spaceCharacter=new SpaceCharacter();
            spaceCharacter.setId(id);
            spaceCharacter.setDeleted(false);
            int updateCount=baseMapper.updateById(spaceCharacter);
            return updateCount;
        }
        return 0;
    }
}
